package offer;

public class offerII_0008 {
    public int minSubArrayLen(int target, int[] nums) {
        int len=nums.length;
        int left=0;
        int right=0;
        int sum=0;
        int min=len+1;
        while(right<len){
            if(sum>=target){
                min=Math.min(min,right-left);
                sum-=nums[left];
                left++;
            }
            else{
                sum+=nums[right];
                right++;
            }
        }
        while(sum>=target){
            min=Math.min(min,right-left);
            sum-=nums[left];
            left++;
        }
        if(min==len+1) return 0;
        return min;
    }
}
